<?php
/**
 * @title 478. 在圆内随机生成点
 * @author start2004
 */

// ini_set("memory_limit", "128M");

// class Solution {
//
//     function find() {
//
//     }
// }

class Solution {
    /**
     * @param Float $radius
     * @param Float $x_center
     * @param Float $y_center
     */
    function __construct($radius, $x_center, $y_center) {
        $this->radius = $radius;
        $this->x = $x_center;
        $this->y = $y_center;
    }

    /**
     * @return Float[]
     */
    function randPoint() {
        while(true){
            /**
             * @since 2022-06-13 随机x, y增幅
             */
            $addX = $this->getRandom();
            $addY = $this->getRandom();

            /**
             * @since 2022-06-13 是否在范围内
             */
            if( ($addX*$addX)+($addY*$addY) > 1){
                continue;
            } else {
                $x = $this->x + $this->radius * $addX;
                $y = $this->y + $this->radius * $addY;

                /**
                 * @return
                 */
                return [$x, $y];
            }
        }
    }

    /**
     * @title 返回随机数[-1, 1]
     * @author start2004
     * @since 2022-06-13 Created
     *
     * @return float|int
     */
    function getRandom(){
        /**
         * @since 2022-06-13 符号
         */
        $f = rand(0,1);

        /**
         * @since 2022-06-13 随机
         */
        $r = rand(0-PHP_INT_MAX, PHP_INT_MAX) / PHP_INT_MAX;

        /**
         * @since 2022-06-13 添加符号
         */
        if($f == 0){
            $r = 0-$r;
        } else {}

        /**
         * @return
         */
        return $r;
    }
}

/**
 * @url http://127.0.0.1/leetcode/202206/2022.06.05.php
 */
$datas = [
    [
        ["Solution","randPoint","randPoint","randPoint"],
        [[1.0, 0.0, 0.0], [], [], []],
    ],
];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
// foreach ($datas as $data){
//     if(count($data) <= 20){
//         var_dump($data);
//     } else {
//         var_dump(count($data));
//     }
//
//     $obj = new Solution();
//     $result = $obj->(...$data);
//     // $result = $obj->($xhprof->tree($data));
//     // $result = $obj->($xhprof->listNode($data));
//     // $result = $obj->find(...$data);
//     var_dump($result);
//     // if(count($result)<=20){
//     //     var_dump($result);
//     // } else {
//     //     var_dump(count($result));
//     // }
//     echo str_repeat(PHP_EOL, 3);
//     echo str_repeat("<br>", 3);
// }

foreach ($datas as $data){
    $obj = new $data[0][0](...$data[1][0]);

    for ($i=1; $i<count($data[0]); $i++){
        $func = $data[0][$i];
        $param = $data[1][$i];
        $result = $obj->$func(...$param);

        echo $data[0][$i] ."(\"". implode(",", $data[1][$i]) ."\") ";
            if($result === true){
                echo "True";
            } elseif($result === false) {
                echo "False";
            } elseif($result === null) {
                echo "Null";
            } elseif(is_array($result)) {
                var_dump($result);
            } else {
                echo $result;
            }
        echo PHP_EOL;
    }

    echo str_repeat(PHP_EOL, 3);
}
$xhprof->end();
